package com.hlw.hr_man.serviceImpl;

import java.util.List;

import com.hlw.hr_man.Model.EmployeeModel;
import com.hlw.hr_man.dao.EmployeeDao;
import com.hlw.hr_man.daoImpl.EmployeeDaoImpl;
import com.hlw.hr_man.service.EmployeeSrevice;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
 * 员工服务的实现
 * @author Administrator
 *
 */
public class EmployeeServiceImpl implements EmployeeSrevice {
	EmployeeDao employeedao=new EmployeeDaoImpl(); //实例化
	
	
    /**
     * 登录时通过员工编号和密码找到员工号
     */
	@Override
	public EmployeeModel findEmpByEnumAndEpwd(String enumber, String epwd) {
		// TODO Auto-generated method stub
		return employeedao.findEmpByEnumAndEpwd(enumber, epwd);
	}
   /**
    *  查询所有员工信息
    */
	@Override
	public JSONObject findAllEmployee(int start, int pageSize) {
		// TODO Auto-generated method stub
		JSONObject employee = new JSONObject();
		employee.put("total", employeedao.getEmployeeCount());
		employee.put("rows", JSONArray.fromObject(employeedao.findAllEmployee(start, pageSize)));
		return employee;
		
	}
	/**
	 * 根据员工名字查询所有员工信息(模糊查询)
	 */
	@Override
	public JSONObject findAllEmployee(int start, int pageSize, String searchname) {
		// TODO Auto-generated method stub
		JSONObject employee = new JSONObject();
		employee.put("total",employeedao.getEmployeeCount(searchname) );
		employee.put("rows", JSONArray.fromObject(employeedao.findAllEmployee(start, pageSize,searchname)));
		return employee;
	}
    /**
     * 根据部门名字查询所有员工信息(重载模糊查询方法)
     */
	@Override
	public JSONObject findAllEmployee(int start, int pageSize, String searchname, String searchtype) {
		// TODO Auto-generated method stub
		JSONObject employee = new JSONObject();
		employee.put("total", employeedao.getEmployeeCount(searchname, searchtype));
		employee.put("rows", JSONArray.fromObject(employeedao.findAllEmployee(start, pageSize, searchname, searchtype)));
		return employee;
	}

    /**
     * 添加员工信息
     */
	@Override
	public int insertEmployee(EmployeeModel emp) {
		// TODO Auto-generated method stub
		return employeedao.insertEmployee(emp);
	}

    /**
     *    得到员工信息
     */
	@Override
	public JSONObject getEmployees(int start, int pageSize) {
		JSONObject   employees = new JSONObject();
		employees.put("total", employeedao.getEmployeesConut());
		employees.put("rows", JSONArray.fromObject(employeedao.getEmployees( start, pageSize)));
		return employees;
	}
	
	/**
	 *  通过员工编号获得员工对象
	 */
	@Override
	public EmployeeModel getEmployeeByEnumber(String e_number) {
		// TODO Auto-generated method stub
		return employeedao.getEmployeeByEnumber(e_number);
	}
	
	/**
	 * 修改员工信息
	 */
	@Override
	public int updateEmployee(EmployeeModel emp) {
		// TODO Auto-generated method stub
		return employeedao.updateEmployee(emp);
	}
	/**
	 * 删除员工信息
	 */
	@Override
	public int deleteEmployees(String[] e_id) {
		// TODO Auto-generated method stub
		return employeedao.deleteEmployees(e_id);
	}
	
	/**
	 * 导入文件加载员工信息
	 */
	@Override
	public boolean uploadEmployees(String path) {
		// TODO Auto-generated method stub
		return employeedao.uploadEmployees(path);
	}

	@Override
	public int updateRoleToNormal(String enumber) {
		// TODO Auto-generated method stub
		return employeedao.updateRoleToNormal(enumber);
	}
	@Override
	public int findEmployeeByRoleid(int roleid) {
		// TODO Auto-generated method stub
		return employeedao.findEmployeeByRoleid(roleid);
	}
	@Override
	public int updateRoleToManger(String e_number,int roleid) {
		// TODO Auto-generated method stub
		return employeedao.updateRoleToManger(e_number,roleid);
	}
	@Override
	public int updateMyInfo(EmployeeModel employee) {
		// TODO Auto-generated method stub
		return employeedao.updateMyInfo(employee);
	}
	@Override
	public int updatePassword(String password, int e_id) {
		// TODO Auto-generated method stub
		return employeedao.upatePassword(password,e_id);
	}
	/**
	 * 验证员工编号是否存在
	 */
	@Override
	public int validateE_number(String e_number) {
		// TODO Auto-generated method stub
		return employeedao.validateE_number(e_number);
	}

}
